/**
 * Copyright (C), 2020, Y2 T205
 * FileName: MyThreadConfig
 * Author: Lenovo
 * Date: 2020-05-25 12:10
 * Description: 线程池的配置
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */


package com.atguigu.gulimall.order.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 〈一句话功能简述〉<br>
 * 〈线程池的配置〉
 *
 * @author Lenovo
 * @create 2020-05-25
 * @since 1.0.0
 */
//@EnableConfigurationProperties(ThreadPoolConfigProperties.class)    //开启属性的配置   与ThreadPoolConfigProperties的类的@conponent的注解要一个就行
@Configuration
public class MyThreadConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
//        从配置文件中获取数据
        return new ThreadPoolExecutor(pool.getCoreSize(),
                pool.getMaxSize(),pool.getKeepAliveTime(),
                TimeUnit.SECONDS,new LinkedBlockingDeque<>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }

}
